// pages/set/serve/pj/pj.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
	  http:getApp().globalData.map,
		num:[0,0,0],
		img:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	wx.getStorage({
		key:'uid',
		success:(e)=>{
			this.setData({
				uid:e.data.uid,
				data:options
			})
		}
	})
  },
  fenshu(e){
  	  let a=this.data.num
  	  a[e.currentTarget.dataset.id].fenshu=e.currentTarget.dataset.id
  	  this.setData({
  		  num:a
  	  })
  },
  changeName(e) {
    console.log(e)
	let a=this.data.num
	a[e.currentTarget.dataset.id]=e.detail.num
	this.setData({
		num:a
	})
  },
  sc(e) {
  	let a = this.data.img
  	if (a.length < 3) {
  		wx.showToast({
  			title: '加载中',
  			icon: 'loading'
  		});
  		let that = this
  		wx.chooseImage({
  			count: 3,
  			sizeType: 'compressed',
  			success: (en) => {
  				console.log(en)
  				en.tempFilePaths.forEach(function(item, index) {
  					wx.uploadFile({
  						url: getApp().globalData.http3,
  						filePath: item,
  						name: 'picturePath',
  						success: function(res) {
  							let c = JSON.parse(res.data)
  							a.push({'path':c.data.headImage})
  							console.log(a)
  							that.setData({
  								img: a
  							})
  							wx.hideToast();
  						}
  					});
  				})
  			}
  		})
  	}
  },
  dete(e) {
  	let a = this.data.img
  	a.splice(e.currentTarget.dataset.id, 1)
  	this.setData({
  		img: a
  	})
  },
  nr(e){
  	this.setData({
  		list:e.detail.value
  	})
  },
  sure(){
	  console.log(this.data.data)
	  let a=[]
	  this.data.img.forEach(function(item,index){
		  a.push(item.path)
	  })
	  a=a.join()
	  wx.request({
	  		  url:getApp().globalData.http+'action=serverOrderPinlun&uid='+this.data.uid+'&oid='+this.data.data.id+
			  '&shopid='+this.data.data.shopid+'&plnr='+this.data.list+'&imgPath='+a+'&speedfs='+this.data.num[0]+
			  '&fuwufs='+this.data.num[1]+'&pricefs='+this.data.num[2],
	  		  success: (e) => {
	  		  	console.log(e)
	  			wx.navigateBack({
	  				delta:1
	  			})
	  		  }
	  })
  }
})